package com.edu.exam.enums.examination;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 导航类型枚举
 *
 * <p>导航操作的类型定义。</p>
 *
 * @author 系统生成
 * @version 1.0
 * @since 2025-11-14
 */
public enum NavigationType implements BaseEnum {

    /** 前进 */
    FORWARD("FORWARD", "前进"),

    /** 后退 */
    BACKWARD("BACKWARD", "后退"),

    /** 跳转 */
    JUMP("JUMP", "跳转"),

    /** 复习 */
    REVIEW("REVIEW", "复习"),

    /** 标记 */
    MARK("MARK", "标记");

    private final String code;
    private final String description;

    NavigationType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static NavigationType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Navigation type code cannot be null or empty");
        }

        for (NavigationType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown navigation type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static NavigationType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Navigation type description cannot be null or empty");
        }

        for (NavigationType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown navigation type description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}